import MainMaskViewUI = layaUI.main.MainMaskViewUI;
import Animation = laya.display.Animation;
import Rectangle = laya.maths.Rectangle;

class MainMaskView extends Panel{
    loadList = ["main"];
    ui : layaUI.main.MainMaskViewUI;
    uiClass = layaUI.main.MainMaskViewUI;
    tParent = UIManager.uiLayer;
    constructor() {
        super();
    }

    private static _instance:MainMaskView;//单例
    private AniConfPath: string = "res/atlas/10001.atlas";
    private ani: Animation;
    /**
     * 获取 单例
     */
    public static getInstance():MainMaskView{
        if(MainMaskView._instance == null){
            MainMaskView._instance = new MainMaskView();
        }
        return MainMaskView._instance;
    }

    /**
     * 初始化
     */
    protected onFirst():void{
        this.ani = new Animation();
    }

    /**
     * 添加到舞台
     */
    protected onShow():void{

        this.ani.loadAtlas(ResUtils.getLoadUrl(this.AniConfPath)); // 加载图集动画
        this.ani.interval = 150; // 设置播放间隔（单位：毫秒）
        this.ani.index = 1; // 当前播放索引
        this.ani.play(); // 播放图集动画

        // 获取动画的边界信息
        var bounds: Rectangle = this.ani.getGraphicBounds();
        this.ani.pivot(bounds.width / 2, bounds.height / 2);

        this.ani.pos(this.ui.width / 2, this.ui.height / 2);

        this.ui.addChild(this.ani);
    }

    /**
     * 从舞台移除
     */
    protected onClose():void{
        this.ani.stop();
    }
}